-- addon_bonus
-- created by chendh
-- 天空战附加属性：天空战属性额外奖励
-- ([plunder:({({1,10000,20}})])代表掠夺玩家时额外获得20个古遗迹碎片
-- ([monster:({({1,10000,20,250}})])代表怪物浮岛战斗胜利时25%的概率额外获得20个古遗迹碎片

return {
    -- 空属性
    getEmptyProp = function()
        return {};
    end,

    -- 合并属性
    mergeSkyProp = function(data, addon)
        local result = {};

        if not data then
            result = table.copy(addon);
        else
            result = table.copy(data);

            for style, value in pairs(addon) do
                if not result[style] then
                    result[style] = {};
                end

                result[style] = table.append(result[style], value);
            end
        end

        return result;
    end,

    parseDesc = function(desc, data)
        -- 按顺序替换，每次替换一个
        local bonusList;
        for _, key in ipairs(table.keys(data)) do
            bonusList = data[key];
            for _, bonus in ipairs(bonusList) do
                -- 奖励数量
                desc = string.gsub(desc, "{amount}", bonus[3], 1);

                -- 如果配置了奖励概率
                if #bonus > 3 then
                    desc = string.gsub(desc, "{rate}", math.modf(bonus[4] / 10), 1);
                end
            end
        end

        return desc;
    end,
};